/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-24 13:09:49
 * @LastEditTime: 2025-02-12 21:00:47
 * @FilePath: /monitor_belt/src/components/authRouter/index.tsx
 */
import { getCache } from "@/utils/storage"
import { Navigate } from "react-router-dom";
import { routers } from "@/routers";
import { matchRoute } from "@/routers/match";

const AuthRouter = (props: { children: JSX.Element }) => {
    let token = getCache('token');
    let { pathname } = location;
    let currentRoute = matchRoute(pathname, routers);
    if (token || currentRoute.path=='/login') {
        return props.children;
    } else {
        return <Navigate to="/login" replace/>
    }
}

export default AuthRouter